# -*- coding: utf-8 -*-

from functools import reduce

def str2float(s):
    DIGITS = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}
    def c2i(c):
        return DIGITS[c] if c in DIGITS else -1
    str1 = s[:s.find('.')]
    str2 = s[:s.find('.'):-1]
    clist1 = list(map(c2i, str1))
    # print(clist1)
    clist2 = list(map(c2i, str2))
    # print(clist2)
    int1 = reduce(lambda x,y:x*10+y, clist1)
    int2 = reduce(lambda x,y:x*0.1+y, clist2)
    return int1 + int2*0.1


print('str2float(\'123.456\') =', str2float('123.456'))
if abs(str2float('123.456') - 123.456) < 0.00001:
    print('测试成功!')
else:
    print('测试失败!')